fix(cli): guard nil file panic in generated download commands - #1241
Open
jablan wants to merge 1 commit into
Open
fix(cli): guard nil file panic in generated download commands#1241jablan wants to merge 1 commit into
jablan wants to merge 1 commit into
Conversation
The API returns 200 with an empty body when a download's tags filter
matches zero translations. The SDK's decode() leaves the *os.File
result nil in that case with no error, but the generated download
commands unconditionally called data.Close()/data.Name() on it,
causing a nil pointer dereference panic, e.g.:
phrase locales download --id en-US --project_id ... \
--file_format properties --tags <tag-matching-nothing>
Same root cause as the earlier pull.go fix, but in the openapi-generator
CLI template, which is shared by every generated command whose return
type is *os.File - so this also covers other download-style endpoints
beyond locale download.
Added spec/locales_download_spec.rb, which reproduces the exact crash
against a mock server. Confirmed it fails with the reported panic
against the pre-fix generated code and passes after regenerating with
the template fix; full spec suite (38 examples) still green.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
API changelog (oasdiff)Doc-only edits (descriptions, examples) do not appear here. |
Sven Dunemann (forelabs)
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A user reported that the latest CLI release panics on
phrase locales downloadwhen a--tagsfilter matches zero translations:This is a sibling issue to #1235 (fixed in
pull.go), but in a different code path: the standalone, per-endpointphrase locales downloadcommand generated fromopenapi-generator/templates/cli/api.handlebars.Root cause: the API returns
200 OKwith an empty body when a filter matches no translations. The SDK'sdecode()leaves the*os.Fileresultnilin that case with no error — a valid empty export, not a failed download. The generated command unconditionally calleddata.Close()/data.Name()on that nil file, causing a nil pointer dereference.Since
cmd/api_*.gofiles are generated (and gitignored — never committed), the fix has to live in the Handlebars template itself, which is shared by every generated command whose return type is*os.File. So this also covers other download-style endpoints beyond locale download, not just the one in the report.Fix
Wrap the file-handling block in
api.handlebarswith adata != nilguard, mirroring the same fix already applied tocopyToDestinationinpull.go.Test plan
spec/locales_download_spec.rb, an integration spec that mocks the download endpoint returning200with an empty body and runs the actual builtphrase-clibinary.npm run generate.go && npm run generate.cli) and confirmed the new spec fails with the exact reported panic against the pre-fix template, and passes after applying the fix.🤖 Generated with Claude Code